﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BF
{
    public static class MonoPool 
    {

        /// <summary>
        /// 初始化Mono对象池
        /// </summary>
        /// <param name="directory">预制体相对于Resources的路径,预制体的上级路径</param>
        public static MonoPool<T> InitPool<T>(string directory) where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Init(directory);
        }

        /// <summary>
        /// 初始化Mono对象池
        /// </summary>
        /// <param name="prefabName">预制体的name</param>
        /// <param name="directory">预制体相对于Resources的路径,预制体的上级路径</param>
        public static MonoPool<T> InitPool<T>(string prefabName, string directory) where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Init(prefabName, directory);
        }

        /// <summary>
        /// 初始化Mono对象池
        /// </summary>
        public static MonoPool<T> InitPool<T>(T prefab) where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Init(prefab);
        }

        /// <summary>
        /// 先准备一定数量的对象
        /// </summary>
        public static MonoPool<T> Prepare<T>(int count) where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Prepare(count) as MonoPool<T>;
        }

        /// <summary>
        /// 先准备一定数量的对象
        /// </summary>
        /// <param name="prefabName">预制体的name</param>
        public static MonoPool<T> Prepare<T>(string prefabName, int count) where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Prepare(prefabName, count);
        }

        /// <summary>
        /// 将对象从池中取出
        /// 注：调用此方法前，请确认池已被初始化<see cref="PoolHelper.InitPool{T}(string)"/>
        /// </summary>
        public static T Pop<T>() where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Pop();
        }

        /// <summary>
        /// 将对象从池中取出
        /// 注：调用此方法前，请确认池已被初始化<see cref="PoolHelper.InitPool{T}(string, string)"/>
        /// </summary>
        /// <param name="name">预制体的name</param>
        public static T Pop<T>(string name) where T : MonoRecycleItem
        {
            return MonoPool<T>.instance.Pop(name);
        }

        /// <summary>
        /// 删除池中所有缓存对象,不包括正在使用的
        /// </summary>
        public static void ClearAllItemCache()
        {
            MonoPoolRoot.instance.ClearAllMonoPoolItemCache();
        }

        public static void ClearAllPool()
        {
            MonoPoolRoot.instance.ClearAllPool();
        }
    }
}